import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class GraphTest_WhiteBox {

    Matrix mt0=new Matrix();
    ExerciseHash Ehash0=new ExerciseHash();
    String finalstr0= "My thanks are due in three quarters.\n" +
            "To the Public, for the indulgent ear it has inclined to a plain tale with few pretensions.\n" +
            "To the Press, for the fair field its honest suffrage has opened to an obscure aspirant.\n" +
            "To my Publishers, for the aid their tact, their energy, their practical sense and frank liberality have afforded an unknown and unrecommended Author.";
    String splitstr0[]=finalstr0.split(" ");



    @Test
    public void calcShortestPathTest1() throws Exception {
        String pathStart="the";
        String pathEnd="to";
        // 起点和终点都找到
        Ehash0.calcletter(finalstr0);
        mt0.Creatematrix(Ehash0, finalstr0);
        Graph G0=new Graph(mt0.size, splitstr0.length-1, mt0);
        int[][] path0=G0.Floyd(mt0);
        String finalPath=G0.calcShortestPath(pathStart, pathEnd, mt0, path0);

        assertEquals("the->indulgent->ear->it->has->inclined->to\n", finalPath);
    }


    @Test
    public void calcShortestPathTest2() throws Exception {
        String pathStart="none";
        String pathEnd="to";
        // 没找到起点，找到终点
        Ehash0.calcletter(finalstr0);
        mt0.Creatematrix(Ehash0, finalstr0);
        Graph G0=new Graph(mt0.size, splitstr0.length-1, mt0);
        int[][] path0=G0.Floyd(mt0);
        String finalPath=G0.calcShortestPath(pathStart, pathEnd, mt0, path0);

        assertEquals("0", finalPath);
    }

    @Test
    public void calcShortestPathTest3() throws Exception {
        String pathStart="the";
        String pathEnd="none";
        // 找到起点，没找到终点
        Ehash0.calcletter(finalstr0);
        mt0.Creatematrix(Ehash0, finalstr0);
        Graph G0=new Graph(mt0.size, splitstr0.length-1, mt0);
        int[][] path0=G0.Floyd(mt0);
        String finalPath=G0.calcShortestPath(pathStart, pathEnd, mt0, path0);

        assertEquals("1", finalPath);
    }

    @Test
    public void calcShortestPathTest4() throws Exception {
        String pathStart="none";
        String pathEnd="none";
        // 起点和终点都没找到
        Ehash0.calcletter(finalstr0);
        mt0.Creatematrix(Ehash0, finalstr0);
        Graph G0=new Graph(mt0.size, splitstr0.length-1, mt0);
        int[][] path0=G0.Floyd(mt0);
        String finalPath=G0.calcShortestPath(pathStart, pathEnd, mt0, path0);

        assertEquals("2", finalPath);
    }
}
